//
//  ZYTextField.m
//  XinJiangMall
//
//  Created by Tzyang on 2018/4/8.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "ZYTextField.h"

@implementation ZYTextField

- (instancetype)initWithFrame:(CGRect)frame
                 placeholder:(NSString *)placeholderStr
                keyboardType:(UIKeyboardType)type
           leftViewImageName:(NSString *)imgStr
                    textEntry:(BOOL)entry{
    
    if (self = [super initWithFrame:frame]) {
        //textField
        self.backgroundColor = WHITE_COLOR;
        self.tintColor = BLACK_COLOR;
        self.textColor = BLACK_COLOR;
        self.placeholder = placeholderStr;
        UILabel * codePlaceholderLabel = [self valueForKey:@"_placeholderLabel"];
        codePlaceholderLabel.font = XJFONTSET_R(15);
        [self setValue:XJCOLOR_RGB(185, 194, 197) forKeyPath:@"_placeholderLabel.textColor"];
        self.font = XJFONTSET_R(15);
        self.secureTextEntry = entry;
        self.keyboardType = type;
        self.returnKeyType = UIReturnKeyDefault;
        self.clearButtonMode=UITextFieldViewModeWhileEditing;

        //左图标
        UIView * leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
        UIImageView * leftImgV = [[UIImageView alloc]initWithFrame:CGRectMake(10, 14, 22, 22)];
        leftImgV.image = [UIImage imageNamed:imgStr];
        [leftView addSubview:leftImgV];
        self.leftView = leftView;
        self.leftViewMode = UITextFieldViewModeAlways;
        //添加下划线
        UIView * bottomLine = [[UIView alloc]initWithFrame:CGRectMake(0,frame.size.height-0.5,frame.size.width,0.5)];
        bottomLine.backgroundColor = XJCOLOR_RGB(221, 221, 221);
        [self addSubview:bottomLine];
    }
    return self;
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

//- (void)drawRect:(CGRect)rect{
//    // Drawing code
//    CGContextRef context = UIGraphicsGetCurrentContext();
//    CGContextSetFillColorWithColor(context, XJCOLOR_RGB(221, 221, 221).CGColor);
//    CGContextFillRect(context, CGRectMake(0, CGRectGetHeight(self.frame) - 1.0, CGRectGetWidth(self.frame), 1.0));
//
//}

@end
